package reflection.proxy;

import java.lang.reflect.Proxy;

/**
 * @program: javase
 * @description: 静态代理
 * @author: lld
 * @create: 2020-11-23 17:04
 **/
public class StaticProxyTest {

    public static void main(String[] args) {
        ClothFactory clothFactory = new ClothFactory();
        ClothProxyFactory clothProxyFactory = new ClothProxyFactory(clothFactory);
        clothProxyFactory.produceCloth();
    }

}

//目标类
class ClothFactory implements Factory {

    @Override
    public void produceCloth() {
        System.out.println("produce Cloth");
    }
}

//代理类
class ClothProxyFactory implements Factory {
    private ClothFactory clothFactory;//使用构造器传入目标对象进行实例化

    public ClothProxyFactory(ClothFactory clothFactory) {
        this.clothFactory = clothFactory;
    }

    @Override
    public void produceCloth() {
        System.out.println("ClothProxyFactory ready");
        //在代理类内部调用目标类方法
        clothFactory.produceCloth();
        System.out.println("ClothProxyFactory end");
    }
}